﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace CartoGraphic.Model
{
    class PolyLineGeo : AbstractGeometry,IDrawItem
    {
        //public string type;
        private double length;
        public List<MyPoint> points;

        public PolyLineGeo(List<MyPoint> points)
        {
            this.dimention = 1;
            this.points = points;
            this.type = "U";
            this.length = 0;
        }

        public override void Draw(Graphics g)
        {
            base.Draw(g);
            if (type.Equals("B"))
                drawB(g);
            else if (type.Equals("C"))
                drawC(g);
            else if (type.Equals("F"))
                drawF(g);
            else if (type.Equals("H"))
                drawH(g);
            else if (type.Equals("R"))
                drawR(g);
            else if (type.Equals("T"))
                drawT(g);
            else if (type.Equals("V"))
                drawV(g);
            else if (type.Equals("U"))
                drawU(g);
        }

        public MyPoint getStartPoint()
        {
            return points[0];
        }

        public MyPoint getEndPoint()
        {
            return points[points.Count - 1];
        }

        public void addPoint(MyPoint p)
        {
            points.Add(p);
        }

        public void setWidth(double width)
        {
            this.width = width;
        }

        public double getWidth()
        {
            return this.width;
        }

        public void cacLength()
        {
            double _length = 0;
            for (int i = 0; i < points.Count - 1; i++)
                _length += Math.Sqrt((points[i].X - points[i + 1].X) * (points[i].X - points[i + 1].X) + (points[i].Y - points[i + 1].Y) * (points[i].Y - points[i + 1].Y));
            this.length = _length;
        }

        public double getLength()
        {
            return this.length;
        }

        public void drawB(Graphics g)
        {
            this.pen.Color = Color.Black;
            this.brush = new SolidBrush(Color.Chocolate);
            Point[] pointss = new Point[this.points.Count];
            for (int i = 0; i < this.points.Count; i++)
            {
                pointss[i].X = this.points[i].sX;
                pointss[i].Y = this.points[i].sY;
            }
            g.DrawCurve(this.pen, pointss);    
            //g.DrawBeziers(this.pen, pointss);
            
        }

        public void drawC(Graphics g)
        {
            this.pen.Color = Color.Black;
            this.brush = new SolidBrush(Color.Black);
            Point[] pointss = new Point[this.points.Count];
            for (int i = 0; i < this.points.Count; i++)
            {
                pointss[i].X = this.points[i].sX;
                pointss[i].Y = this.points[i].sY;
            }
            g.DrawCurve(this.pen, pointss);
        }

        public void drawF(Graphics g)
        {
            this.pen.Color = Color.Black;
            this.brush = new SolidBrush(Color.Black);
            Point[] pointss = new Point[this.points.Count];
            for (int i = 0; i < this.points.Count; i++)
            {
                pointss[i].X = this.points[i].sX;
                pointss[i].Y = this.points[i].sY;
            }
            g.DrawCurve(this.pen, pointss);
        }

        public void drawH(Graphics g)
        {
            this.pen.Color = Color.Black;
            this.brush = new SolidBrush(Color.FromArgb(150, 247, 247));
            Point[] pointss = new Point[this.points.Count];
            for (int i = 0; i < this.points.Count; i++)
            {
                pointss[i].X = this.points[i].sX;
                pointss[i].Y = this.points[i].sY;
            }
            g.DrawCurve(this.pen, pointss);
        }

        public void drawR(Graphics g)
        {
            this.pen.Color = Color.Black;
            this.brush = new SolidBrush(Color.Black);
            Point[] pointss = new Point[this.points.Count];
            for (int i = 0; i < this.points.Count; i++)
            {
                pointss[i].X = this.points[i].sX;
                pointss[i].Y = this.points[i].sY;
            }
            g.DrawCurve(this.pen, pointss);
        }

        public void drawT(Graphics g)
        {
            this.pen.Color = Color.Black;
            this.brush = new SolidBrush(Color.FromArgb(216, 255, 185));
            Point[] pointss = new Point[this.points.Count];
            for (int i = 0; i < this.points.Count; i++)
            {
                pointss[i].X = this.points[i].sX;
                pointss[i].Y = this.points[i].sY;
            }
            g.DrawCurve(this.pen, pointss);
        }

        public void drawV(Graphics g)
        {
            this.pen.Color = Color.Black;
            this.brush = new SolidBrush(Color.FromArgb(216, 255, 185));
            Point[] pointss = new Point[this.points.Count];
            for (int i = 0; i < this.points.Count; i++)
            {
                pointss[i].X = this.points[i].sX;
                pointss[i].Y = this.points[i].sY;
            }
            g.DrawCurve(this.pen, pointss);
        }

        public void drawU(Graphics g)
        {
            this.pen.Color = Color.Black;
            this.brush = new SolidBrush(Color.Black);
            Point[] pointss = new Point[this.points.Count];
            for (int i = 0; i < this.points.Count; i++)
            {
                pointss[i].X = this.points[i].sX;
                pointss[i].Y = this.points[i].sY;
            }
            g.DrawCurve(this.pen, pointss);
        }
    }
}
